// =================
// Prep Age Dataset
// =================

clear
import excel using "./input/prohibition/cities_dry_wdates.xlsx", first

** SETUP
expand 60
bys gen_id: gen time = _n
gen f_yr = floor((time-1)/12)+1916
gen f_m = mod(time,12)
replace f_m = 12 if f_m==0

gen 	f_myr = ym(f_yr, f_m)
format 	f_myr %tm

xtset gen_id f_myr

** CODE PROHIBITION 
* Two variants based on when prohibition is assumed to turn on
gen proh_18th = .
gen proh_wpa = . 

* for early adopters except KC (all cnty_dry_1916=1 except Kansas City, MO gen_id=16)
replace proh_18th = 1 if cnty_dry_1916==1 & gen_id!=16
replace proh_wpa = 1 if cnty_dry_1916==1 & gen_id!=16
tab proh_18th proh_wpa

* For Wartime adopters except KC  
replace proh_18th = 0 if wartime==1 & gen_id!=16 & tin(1910m1,1920m1)
replace proh_18th = 1 if wartime==1 & gen_id!=16 & tin(1920m2,1930m1)

replace proh_wpa = 0 if wartime==1 & gen_id!=16 & tin(1910m1,1919m6)
replace proh_wpa = 1 if wartime==1 & gen_id!=16 & tin(1919m7,1930m1)

tab proh_18th proh_wpa

* Code KC 
replace proh_18th = 0 if gen_id==16 & tin(1917m1,1920m1)
replace proh_18th = 1 if gen_id==16 & (tin(1910m1,1916m12) | tin(1910m2,1930m1))

replace proh_wpa = 0 if gen_id==16 & tin(1917m1,1919m6)
replace proh_wpa = 1 if gen_id==16 & (tin(1910m1,1916m12) | tin(1920m7,1930m1))

tab proh_18th proh_wpa

* Code DC (gen id=42)

replace proh_18th = 0 if gen_id==42 & tin(1910m1,1917m10)
replace proh_18th = 1 if gen_id==42 & tin(1917m11,1930m1)

replace proh_wpa = 0 if gen_id==42 & tin(1910m1,1917m10)
replace proh_wpa = 1 if gen_id==42 & tin(1917m11,1930m1)

tab proh_18th proh_wpa

* Code remaining states

foreach y of numlist 1916/1920 {
	replace proh_18th = cnty_dry_`y' if mi(proh_18th) & f_yr==`y'
	replace proh_wpa = cnty_dry_`y' if mi(proh_wpa) & f_yr==`y'
}

tab proh_18th proh_wpa

keep gen_id f_myr proh_*

compress 
save 	"./output/cities_prohibition.dta", replace

clear

